/**
  * 个人中心
  */
module game {
    export class UserCenterMediator extends BaseMediator {
        public static NAME: string = "UserCenterMediator";
        private gameType: string = "";
        public constructor(viewComponent: any = null) {
            super(UserCenterMediator.NAME, viewComponent);
        }

        public listNotificationInterests(): Array<any> {
            return [
                PanelNotify.HALL.STAGE_RESIZE,
                PanelNotify.HALL.OPEN_USER_CENTER,
                PanelNotify.HALL.CLOSE_USER_CENTER,
                PanelNotify.HALL.REFRESH_USER_INFO
            ];
        }
        private panel: userCenterPanel;
        public handleNotification(notification: puremvc.INotification): void {
            this.gameType = notification.getBody();
            switch (notification.getName()) {
                case PanelNotify.HALL.STAGE_RESIZE:
                    if (this.panel) {
                        this.panel.width = GameConfig.curWidth()
                        this.panel.height = GameConfig.curHeight()
                    }
                    break;
                case PanelNotify.HALL.OPEN_USER_CENTER: {
                    this.panel = null;
                    this.panel = new userCenterPanel();
                    this.showUI(this.panel, 2, 1, true);
                    break;
                }
                case PanelNotify.HALL.CLOSE_USER_CENTER: {
                    this.closePanel(0);
                    break;
                }
                case PanelNotify.HALL.REFRESH_USER_INFO:
                    if (this.panel && this.panel.parent) {
                        this.panel.userIcon.source = "special_" + GameVO.getVo().wFaceID % 15;
                    }
                    break;
            }
        }

        /**
         * 初始化面板ui
         */
        public initUI(): void {
            this.panel.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closeButtonClick, this);

            this.panel.grxx.addEventListener(egret.TouchEvent.TOUCH_TAP, this.typeClick, this);
            this.panel.tzjl.addEventListener(egret.TouchEvent.TOUCH_TAP, this.typeClick, this);
            this.panel.zhmx.addEventListener(egret.TouchEvent.TOUCH_TAP, this.typeClick, this);
            this.panel.grbb.addEventListener(egret.TouchEvent.TOUCH_TAP, this.typeClick, this);
            this.panel.vip.addEventListener(egret.TouchEvent.TOUCH_TAP, this.typeClick, this);

            this.panel.edit1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.edit1Click, this);
            this.panel.edit2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.edit2Click, this);
            this.panel.vipUpPage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.modifyVipLeve, this);
            this.panel.vipNextPage.addEventListener(egret.TouchEvent.TOUCH_TAP, this.modifyVipLeve, this);
            this.panel.getLiJin1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lingqujiangliClick, this);
            this.panel.getLiJin2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lingqujiangliClick, this);
            this.panel.getLiJin3.addEventListener(egret.TouchEvent.TOUCH_TAP, this.lingqujiangliClick, this);
            this.panel.userIcon.addEventListener(egret.TouchEvent.TOUCH_TAP, this.userIconClick, this);

            this.panel.tzjlTimeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.tzjlShowSelect, this);
            this.panel.tzjlTypeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.tzjlShowSelect, this);

            this.panel.zhmxTimeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.zhmxShowSelect, this);
            this.panel.zhmxTypeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.zhmxShowSelect, this);

            this.panel.grbbTimeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.grbbShowSelect, this);


        }

        /**
         * 初始化面板数据
         */
        private tzjl_keys_time = [
            { key: "0", value: "全部时间" },
            { key: "1", value: "今日" },
            { key: "2", value: "昨日" },
            { key: "3", value: "一个月内" },
        ]

        private tzjl_keys_type = [
            { key: "0", value: "全部" },
            { key: "200", value: "斗地主" },
            { key: "27", value: "抢庄牛牛" },
            { key: "104", value: "百人牛牛" },
            { key: "6", value: "炸金花" },
            { key: "122", value: "百家乐" },
            { key: "150", value: "龙虎斗" },
            { key: "89", value: "红黑大战" },
            { key: "120", value: "二八杠" }
        ]
        private zhmx_keys_time = [
            { key: "-1", value: "全部时间" },
            { key: "1", value: "今日" },
            { key: "2", value: "昨日" },
            { key: "3", value: "一个月内" },
        ]
        private zhmx_keys_type = [
            { key: "-1", value: "全部" },
            { key: "1", value: "游戏注册" },
            { key: "2", value: "游戏赠送" },
            { key: "3", value: "游戏结算" },
            { key: "4", value: "游戏充值" },
            { key: "5", value: "提现" },
            { key: "6", value: "保险箱记录" },
            { key: "7", value: "代理抽水" },
        ]

        private grbb_keys_time = [
            { key: "1", value: "今日" },
            { key: "2", value: "昨日" },
            { key: "3", value: "一个月内" },
        ]
        public initData(): void {
            //初始化各个子界面的下拉多选栏选项
            this.typeClick(null)
            //初始化投注记录 下拉选项栏
            this.panel.tzjlTimeLab.name = "1"
            this.panel.tzjlTimeLab.text = "今日"
            this.panel.tzjlTypeLab.name = "0"
            this.panel.tzjlTypeLab.text = "全部"
            for (var i = 0; i < this.tzjl_keys_time.length; i++) {
                var lab = new eui.Label(this.tzjl_keys_time[i].value)
                lab.size = 24
                lab.textAlign = "center"
                lab.verticalAlign = "middle"
                lab.border = true
                lab.borderColor = 0xFFFFFF
                lab.name = this.tzjl_keys_time[i].key;
                this.panel.tzjlTimeGroup.addChild(lab);
                lab.addEventListener(egret.TouchEvent.TOUCH_TAP, this.tzjlTimeSelect, this)
            }
            for (var i = 0; i < this.tzjl_keys_type.length; i++) {
                var lab = new eui.Label(this.tzjl_keys_type[i].value)
                lab.size = 24
                lab.textAlign = "center"
                lab.verticalAlign = "middle"
                lab.border = true
                lab.borderColor = 0xFFFFFF
                lab.name = this.tzjl_keys_type[i].key;
                this.panel.tzjlTypeGroup.addChild(lab);
                lab.addEventListener(egret.TouchEvent.TOUCH_TAP, this.tzjlTypeSelect, this)
            }
            //初始化账户明细 下拉选项栏
            this.panel.zhmxTimeLab.name = "1"
            this.panel.zhmxTimeLab.text = "今日"
            this.panel.zhmxTypeLab.name = "-1"
            this.panel.zhmxTypeLab.text = "全部"
            for (var i = 0; i < this.zhmx_keys_time.length; i++) {
                var lab = new eui.Label(this.zhmx_keys_time[i].value)
                lab.size = 24
                lab.textAlign = "center"
                lab.verticalAlign = "middle"
                lab.border = true
                lab.borderColor = 0xFFFFFF
                lab.name = this.zhmx_keys_time[i].key;
                this.panel.zhmxTimeGroup.addChild(lab);
                lab.addEventListener(egret.TouchEvent.TOUCH_TAP, this.zhmxTimeSelect, this)
            }
            for (var i = 0; i < this.zhmx_keys_type.length; i++) {
                var lab = new eui.Label(this.zhmx_keys_type[i].value)
                lab.size = 24
                lab.textAlign = "center"
                lab.verticalAlign = "middle"
                lab.border = true
                lab.borderColor = 0xFFFFFF
                lab.name = this.zhmx_keys_type[i].key;
                this.panel.zhmxTypeGroup.addChild(lab);
                lab.addEventListener(egret.TouchEvent.TOUCH_TAP, this.zhmxTypeSelect, this)
            }
            //初始化个人报表
            this.panel.grbbTimeLab.name = "1"
            this.panel.grbbTimeLab.text = "今日"
            for (var i = 0; i < this.grbb_keys_time.length; i++) {
                var lab = new eui.Label(this.grbb_keys_time[i].value)
                lab.size = 24
                lab.textAlign = "center"
                lab.verticalAlign = "middle"
                lab.border = true
                lab.borderColor = 0xFFFFFF
                lab.name = this.grbb_keys_time[i].key;
                this.panel.grbbTimeGroup.addChild(lab);
                lab.addEventListener(egret.TouchEvent.TOUCH_TAP, this.grbbTimeSelect, this)
            }
        }
        private closeButtonClick(event: egret.TouchEvent): void {
            SoundManage.startAnniuBtnLoad();
            this.closePanel(1);
        }

        //切换标签页
        private typeClick(event: egret.TouchEvent) {
            this.panel.grxx.touchEnabled = true
            this.panel.tzjl.touchEnabled = true
            this.panel.zhmx.touchEnabled = true
            this.panel.grbb.touchEnabled = true
            this.panel.vip.touchEnabled = true

            this.panel.grxx.icon = "userCenter_grxx"
            this.panel.tzjl.icon = "userCenter_tzjl"
            this.panel.zhmx.icon = "userCenter_zhmx"
            this.panel.grbb.icon = "userCenter_grbb"
            this.panel.vip.icon = "userCenter_vipxq"

            this.panel.grxx_vive.visible = false
            this.panel.tzjl_vive.visible = false
            this.panel.zhmx_vive.visible = false
            this.panel.grbb_vive.visible = false
            this.panel.vip_vive.visible = false

            if (event == null || event.currentTarget == this.panel.grxx) {
                this.panel.grxx.touchEnabled = false
                this.panel.grxx.icon = "userCenter_grxx_x"
                this.panel.grxx_vive.visible = true
                this.grxxClick();
            } else if (event.currentTarget == this.panel.tzjl) {
                this.panel.tzjl.touchEnabled = false
                this.panel.tzjl.icon = "userCenter_tzjl_x"
                this.panel.tzjl_vive.visible = true
                this.tzjlFind()
            } else if (event.currentTarget == this.panel.zhmx) {
                this.panel.zhmx.touchEnabled = false
                this.panel.zhmx.icon = "userCenter_zhmx_x"
                this.panel.zhmx_vive.visible = true
                this.zhmxFind()
            } else if (event.currentTarget == this.panel.grbb) {
                this.panel.grbb.touchEnabled = false
                this.panel.grbb.icon = "userCenter_grbb_x"
                this.panel.grbb_vive.visible = true
                this.grbbFind()
            } else if (event.currentTarget == this.panel.vip) {
                this.panel.vip.touchEnabled = false
                this.panel.vip.icon = "userCenter_vipxq_x"
                this.panel.vip_vive.visible = true
            }
        }
        //查询个人信息
        private grxxClick() {
            var time = Math.floor(Global.getCurrTimeLong() / 1000)
            var signature = Global.getSynLoginKey(time)
            signature = signature.toUpperCase()
            var request = new egret.HttpRequest();
            request.responseType = egret.HttpResponseType.TEXT;
            request.open(InstructionsEnum.IP_API + "/PersonalCenter/GetUserInfomation?userid=" + GameVO.getVo().dwUserID + "&signature=" + signature + "&time=" + time, egret.HttpMethod.POST);
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.addEventListener(egret.Event.COMPLETE, (event: egret.Event) => {
                EffectUtils.hideWaritPanel()
                try {
                    var request = <egret.HttpRequest>event.currentTarget;
                    var obj = JSON.parse(request.response)
                    if (obj.code == 0) {
                        this.showGrxxView(obj);
                    } else {
                        Global.tipShow(obj.mess)
                    }
                } catch (err) {
                    EffectUtils.textFadeAway("数据包异常，无法解析!")
                }
            }, this);
            request.addEventListener(egret.IOErrorEvent.IO_ERROR, () => {
                EffectUtils.hideWaritPanel()
                Global.tipShow("网络请求失败，请稍后重试!")
            }, this);
            EffectUtils.showWaritPanel()
            request.send();
        }
        private handselInfomations: Array<any> = [];
        private selectVipLeve = 1;//当前选择要查看的VIP等级
        //显示个人资料
        private showGrxxView(obj: Object) {
            var data = obj["data"];
            this.handselInfomations = data["handselInfomations"];
            var VIPIndex = data["VIPIndex"];
            var GradeNeedDaMaLiang = data["GradeNeedDaMaLiang"];//当前等级最大打码量，
            var NeedDaMaLiangToNextGrade = data["NeedDaMaLiangToNextGrade"];//当前离升级打码量  GradeNeedDaMaLiang - NeedDaMaLiangToNextGrade = 已有打码量
            var UserAccount = data["UserAccount"];//账号
            var UserRealName = data["UserRealName"];//真实姓名
            var UserNickName = data["UserNickName"];//昵称
            var UserGender = data["UserGender"];//性别
            var UserBirthday = data["UserBirthday"];//生日
            var UserEmail = data["UserEmail"];//邮件
            var UserPhone = data["UserPhone"];//手机
            var UserQQ = data["UserQQ"];//QQ
            var UserWechat = data["UserWechat"];//微信
            this.panel.vipLeveLab.text = "当前会员等级:VIP" + VIPIndex
            this.panel.vipLeveIcon.source = "userCenter_vip_" + VIPIndex
            this.panel.vipLeve.source = "userCenter_vip" + VIPIndex
            this.panel.vipLeveUpTip.text = "还差" + NeedDaMaLiangToNextGrade + "打码升级到VIP" + (VIPIndex + 1)
            if (VIPIndex >= 10) {
                this.panel.vipLeveNext.source = ""
                this.panel.vipLeveUpTip.text = ""
            } else {
                this.panel.vipLeveNext.source = "userCenter_vip" + (VIPIndex + 1)
            }
            this.panel.vipExperience.maximum = GradeNeedDaMaLiang
            this.panel.vipExperience.minimum = ((GradeNeedDaMaLiang * 100) - (NeedDaMaLiangToNextGrade * 100)) / 100
            this.panel.userIcon.source = "special_" + GameVO.getVo().wFaceID % 15;
            this.panel.userAccess.text = UserAccount
            this.panel.userName.text = UserRealName + ""
            this.panel.userNikeName.text = UserNickName
            this.panel.userBirthday.text = UserBirthday
            this.panel.userMail.text = UserEmail
            this.panel.userQQ.text = UserQQ
            this.panel.userWx.text = UserWechat
            this.panel.userPhone.text = UserPhone
            if (UserGender == 1) {
                this.panel.userSex.text = "男"
                this.panel.selectSex1.selected = true
            } else {
                this.panel.selectSex2.selected = true
                this.panel.userSex.text = "女"
            }
            this.selectVipLeve = VIPIndex
            this.modifyVipLeve(null)
        }
        //左右切换VIP等级
        private modifyVipLeve(eve: egret.TouchEvent) {
            if (eve != null) {
                if (eve.currentTarget == this.panel.vipUpPage) {
                    this.selectVipLeve--
                }
                if (eve.currentTarget == this.panel.vipNextPage) {
                    this.selectVipLeve++
                }
            }
            //先左右按钮都启用，如果超限，则禁用其中一个
            this.panel.vipUpPage.touchEnabled = true
            this.panel.vipUpPage.visible = true
            this.panel.vipNextPage.touchEnabled = true
            this.panel.vipNextPage.visible = true
            //控制上下限
            if (this.selectVipLeve <= 1) {
                this.selectVipLeve = 1
                this.panel.vipUpPage.touchEnabled = false
            }
            if (this.selectVipLeve >= 10) {
                this.selectVipLeve = 10
                this.panel.vipNextPage.visible = false;
            }
            this.panel.vipUpPage.icon = "userCenter_v" + this.selectVipLeve;
            this.panel.vipNextPage.icon = this.selectVipLeve >= 10 ? "" : "userCenter_v" + (this.selectVipLeve + 1);//已选中10级的话 右边按钮不显示
            if (this.handselInfomations && this.handselInfomations.length >= 10) {
                var data = this.handselInfomations[this.selectVipLeve - 1]
                this.panel.jinJiLiJin.text = data["Handsel"] + ""
                this.panel.zhouLiJin.text = data["WeekHandsel"] + ""
                this.panel.yueLiJin.text = data["MonthHandsel"] + ""
                var IsHandselCanReceived = data["IsHandselCanReceived"]
                var IsWeekHandselCanReceived = data["IsWeekHandselCanReceived"]
                var IsMonthHandselCanReceived = data["IsMonthHandselCanReceived"]
                if (IsHandselCanReceived == true) {//	是否可以领取升级彩金
                    this.panel.getLiJin1.icon = "userCenter_kelq"
                    this.panel.getLiJin1.touchEnabled = true
                } else {
                    this.panel.getLiJin1.icon = "userCenter_buklq"
                    this.panel.getLiJin1.touchEnabled = false
                }
                if (IsWeekHandselCanReceived == true) {//是否可以领取周礼金
                    this.panel.getLiJin2.icon = "userCenter_kelq"
                    this.panel.getLiJin2.touchEnabled = true
                } else {
                    this.panel.getLiJin2.icon = "userCenter_buklq"
                    this.panel.getLiJin2.touchEnabled = false
                }
                if (IsMonthHandselCanReceived == true) {//是否可以领取月礼金
                    this.panel.getLiJin3.icon = "userCenter_kelq"
                    this.panel.getLiJin3.touchEnabled = true
                } else {
                    this.panel.getLiJin3.icon = "userCenter_buklq"
                    this.panel.getLiJin3.touchEnabled = false
                }
            }
        }
        //打开个人资料修改
        private edit1Click() {
            if (this.panel.edit1.icon == "userCenter_bianji") {
                this.panel.edit1.icon = "userCenter_finishi"
                this.panel.userNikeName.touchEnabled = true;
                this.panel.userNikeName.border = true;
                this.panel.userBirthday.touchEnabled = true;
                this.panel.userBirthday.border = true;
                this.panel.userBirthdayShiLi.visible = true;
                this.panel.selectSex1.visible = true
                this.panel.selectSex2.visible = true;
            } else {
                this.panel.edit1.icon = "userCenter_bianji"
                this.panel.userNikeName.touchEnabled = false;
                this.panel.userNikeName.border = false;
                this.panel.userBirthday.touchEnabled = false;
                this.panel.userBirthday.border = false;
                this.panel.userBirthdayShiLi.visible = false;
                this.panel.selectSex1.visible = false
                this.panel.selectSex2.visible = false;
                this.edit1Send();
            }
        }
        //修改个人资料发送
        private edit1Send() {
            var nikeName = this.panel.userNikeName.text;
            var Birthday = this.panel.userBirthday.text;
            var sex = null;
            if (this.panel.selectSex1.selected == true) {
                sex = 1
                this.panel.userSex.text = "男"
            } else {
                sex = 0
                this.panel.userSex.text = "女"
            }
            var time = Math.floor(Global.getCurrTimeLong() / 1000)
            var signature = Global.getSynLoginKey(time)
            signature = signature.toUpperCase()
            var request = new egret.HttpRequest();
            request.responseType = egret.HttpResponseType.TEXT;
            request.open(InstructionsEnum.IP_API + "/PersonalCenter/H5ModifyUserInformation?userid=" + GameVO.getVo().dwUserID + "&signature=" + signature + "&time=" + time, egret.HttpMethod.POST);
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.addEventListener(egret.Event.COMPLETE, (event: egret.Event) => {
                EffectUtils.hideWaritPanel()
                try {
                    var request = <egret.HttpRequest>event.currentTarget;
                    var obj = JSON.parse(request.response)
                    if (obj.code == 0) {
                        EffectUtils.textFadeAway("修改完成!")
                        // this.grxxClick()//刷新个人信息界面
                        this.sendNotification(PanelNotify.HALL.FIND_USER_NAME)
                    } else {
                        Global.tipShow(obj.mess)
                    }
                } catch (err) {
                    EffectUtils.textFadeAway("数据包异常，无法解析!")
                }
            }, this);
            request.addEventListener(egret.IOErrorEvent.IO_ERROR, () => {
                EffectUtils.hideWaritPanel()
                Global.tipShow("网络请求失败，请稍后重试!")
            }, this);
            EffectUtils.showWaritPanel()
            var obj = { "ModifyInfoType": 1, "Gender": sex, "UserBirthday": Birthday, "UserNickName": nikeName }
            request.send(JSON.stringify(obj));
        }
        //打开联系方式修改
        private edit2Click() {
            if (this.panel.edit2.icon == "userCenter_bianji") {
                this.panel.edit2.icon = "userCenter_finishi"
                this.panel.userMail.touchEnabled = true;
                this.panel.userMail.border = true;
                this.panel.userQQ.touchEnabled = true;
                this.panel.userQQ.border = true;
                this.panel.userWx.touchEnabled = true;
                this.panel.userWx.border = true;
            } else {
                this.panel.edit2.icon = "userCenter_bianji"
                this.panel.userMail.touchEnabled = false;
                this.panel.userMail.border = false;
                this.panel.userQQ.touchEnabled = false;
                this.panel.userQQ.border = false;
                this.panel.userWx.touchEnabled = false;
                this.panel.userWx.border = false;
                this.edit2Send();
            }
        }
        //修改联系方式发送
        private edit2Send() {
            var userMail = this.panel.userMail.text;
            var userQQ = this.panel.userQQ.text;
            var userWx = this.panel.userWx.text;
            var time = Math.floor(Global.getCurrTimeLong() / 1000)
            var signature = Global.getSynLoginKey(time)
            signature = signature.toUpperCase()
            var request = new egret.HttpRequest();
            request.responseType = egret.HttpResponseType.TEXT;
            request.open(InstructionsEnum.IP_API + "/PersonalCenter/H5ModifyUserInformation?userid=" + GameVO.getVo().dwUserID + "&signature=" + signature + "&time=" + time, egret.HttpMethod.POST);
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.addEventListener(egret.Event.COMPLETE, (event: egret.Event) => {
                EffectUtils.hideWaritPanel()
                try {
                    var request = <egret.HttpRequest>event.currentTarget;
                    var obj = JSON.parse(request.response)
                    if (obj.code == 0) {
                        EffectUtils.textFadeAway("修改完成!")
                        this.grxxClick()//刷新个人信息界面
                    } else {
                        Global.tipShow(obj.mess)
                    }
                } catch (err) {
                    EffectUtils.textFadeAway("数据包异常，无法解析!")
                }
            }, this);
            request.addEventListener(egret.IOErrorEvent.IO_ERROR, () => {
                EffectUtils.hideWaritPanel()
                Global.tipShow("网络请求失败，请稍后重试!")
            }, this);
            EffectUtils.showWaritPanel()
            var obj = { "ModifyInfoType": 2, "UserQQ": userQQ, "UserWechart": userWx, "UserEmail": userMail }
            request.send(JSON.stringify(obj));
        }
        //点击申请提取奖励
        private lingqujiangliClick(eve: egret.TouchEvent) {
            var OperatorType = 0;//领取类型【1、晋级彩金；2、周礼金；4、月礼金；】
            if (eve.currentTarget == this.panel.getLiJin1) {
                OperatorType = 1
            }
            if (eve.currentTarget == this.panel.getLiJin2) {
                OperatorType = 2
            }
            if (eve.currentTarget == this.panel.getLiJin3) {
                OperatorType = 4
            }
            var time = Math.floor(Global.getCurrTimeLong() / 1000)
            var signature = Global.getSynLoginKey(time)
            signature = signature.toUpperCase()
            var request = new egret.HttpRequest();
            request.responseType = egret.HttpResponseType.TEXT;
            request.open(InstructionsEnum.IP_API + "/PersonalCenter/H5ReceiveGradeAward?userid=" + GameVO.getVo().dwUserID + "&signature=" + signature + "&time=" + time, egret.HttpMethod.POST);
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.addEventListener(egret.Event.COMPLETE, (event: egret.Event) => {
                EffectUtils.hideWaritPanel()
                try {
                    var request = <egret.HttpRequest>event.currentTarget;
                    var obj = JSON.parse(request.response)
                    if (obj.code == 0) {
                        EffectUtils.textFadeAway("领取成功!")
                        this.grxxClick()//刷新个人信息界面
                        var t = egret.setTimeout(() => {//刷新大厅金币
                            game.AppFacade.instance.sendNotification(PanelNotify.HALL.FIND_USER_MONEY)
                            egret.clearTimeout(t)
                        }, this, 500)
                    } else {
                        Global.tipShow(obj.mess)
                    }
                } catch (err) {
                    EffectUtils.textFadeAway("数据包异常，无法解析!")
                }
            }, this);
            request.addEventListener(egret.IOErrorEvent.IO_ERROR, () => {
                EffectUtils.hideWaritPanel()
                Global.tipShow("网络请求失败，请稍后重试!")
            }, this);
            EffectUtils.showWaritPanel()
            var obj = {
                OperatorType: OperatorType,
                VipID: this.selectVipLeve
            }
            request.send(JSON.stringify(obj));
        }
        //打开头像设置
        private userIconClick(event: egret.TouchEvent) {
            SoundManage.startAnniuBtnLoad();
            EffectUtils.playDim(event.currentTarget)
            game.AppFacade.instance.sendNotification(PanelNotify.HALL.OPEN_SPECIA_MODIFY)
        }

        //显示投注记录的下拉栏
        private tzjlShowSelect(eve: egret.TouchEvent) {
            if (eve.currentTarget == this.panel.tzjlTimeBtn) {
                if (this.panel.tzjlTimeVive.visible) {
                    this.panel.tzjlTimeVive.visible = false
                } else {
                    this.panel.tzjlTimeVive.visible = true
                }
            }
            if (eve.currentTarget == this.panel.tzjlTypeBtn) {
                if (this.panel.tzjlTypeVive.visible) {
                    this.panel.tzjlTypeVive.visible = false
                } else {
                    this.panel.tzjlTypeVive.visible = true
                }
            }
            EffectUtils.playDim(eve.currentTarget)
        }
        //投注记录 - 选择时间
        private tzjlTimeSelect(eve: egret.TouchEvent) {
            this.panel.tzjlTimeLab.text = eve.currentTarget.text;
            this.panel.tzjlTimeLab.name = eve.currentTarget.name;
            this.panel.tzjlTimeVive.visible = false
            this.tzjlFind()
        }
        //投注记录 - 选择类型
        private tzjlTypeSelect(eve: egret.TouchEvent) {
            this.panel.tzjlTypeLab.text = eve.currentTarget.text;
            this.panel.tzjlTypeLab.name = eve.currentTarget.name;
            this.panel.tzjlTypeVive.visible = false
            this.tzjlFind()
        }
        //查询投注记录
        private tzjlFind() {
            var cycle = this.panel.tzjlTimeLab.name;
            var kindid = this.panel.tzjlTypeLab.name
            var time = Math.floor(Global.getCurrTimeLong() / 1000)
            var signature = Global.getSynLoginKey(time)
            signature = signature.toUpperCase()
            var request = new egret.HttpRequest();
            request.responseType = egret.HttpResponseType.TEXT;
            request.open(InstructionsEnum.IP_API + "/gameinfo/AppGetDrawScore?uid=" + GameVO.getVo().dwUserID + "&signature=" + signature + "&time=" + time + "&cycle=" + cycle + "&kindid=" + kindid, egret.HttpMethod.POST);
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.addEventListener(egret.Event.COMPLETE, (event: egret.Event) => {
                EffectUtils.hideWaritPanel()
                try {
                    var request = <egret.HttpRequest>event.currentTarget;
                    var obj = JSON.parse(request.response)
                    if (obj.code == 0) {
                        this.showTzjl(obj);
                    } else {
                        Global.tipShow(obj.msg)
                    }
                } catch (err) {
                    EffectUtils.textFadeAway("数据包异常，无法解析!")
                }
            }, this);
            request.addEventListener(egret.IOErrorEvent.IO_ERROR, () => {
                EffectUtils.hideWaritPanel()
                Global.tipShow("网络请求失败，请稍后重试!")
            }, this);
            EffectUtils.showWaritPanel()
            request.send();
        }
        //显示投注记录
        private showTzjl(obj: any) {
            var map: Array<any> = obj["map"];
            this.panel.tzjl_dataGroup.removeChildren();
            if (map.length == 0) {
                this.panel.tzjl_wushuju.visible = true;
            } else {
                this.panel.tzjl_wushuju.visible = false;
                var y = 10
                for (var i = 0; i < map.length; i++) {
                    var InsertTime = map[i]["InsertTime"]
                    var SerialNumber = map[i]["SerialNumber"]
                    var TotalScore = map[i]["TotalScore"]
                    var Score = map[i]["Score"]

                    var lab1 = new eui.Label(InsertTime + "")
                    lab1.x = 0;
                    lab1.y = y;
                    lab1.size = 18
                    lab1.width = 210
                    lab1.textAlign = "center";
                    lab1.textColor = 0x80bf46
                    lab1.fontFamily = "Microsoft YaHei"
                    this.panel.tzjl_dataGroup.addChild(lab1)
                    var lab2 = new eui.Label(SerialNumber + "")
                    lab2.x = 205;
                    lab2.y = y;
                    lab2.size = 18
                    lab2.width = 300
                    lab2.textAlign = "center";
                    lab2.textColor = 0x80bf46
                    lab2.fontFamily = "Microsoft YaHei"
                    this.panel.tzjl_dataGroup.addChild(lab2)
                    lab2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.copySerialNumber, this)
                    var lab3 = new eui.Label(TotalScore + "")
                    lab3.x = 500;
                    lab3.y = y;
                    lab3.size = 18
                    lab3.width = 260
                    lab3.textAlign = "center";
                    lab3.textColor = 0xEDB561
                    lab3.fontFamily = "Microsoft YaHei"
                    this.panel.tzjl_dataGroup.addChild(lab3)
                    var lab4 = new eui.Label(Score + "")
                    lab4.x = 770;
                    lab4.y = y;
                    lab4.size = 18
                    lab4.width = 200
                    lab4.textAlign = "center";
                    lab4.fontFamily = "Microsoft YaHei"
                    lab4.textColor = Number(Score) > 0 ? 0x8AFF00 : 0xFF0000
                    this.panel.tzjl_dataGroup.addChild(lab4)
                    y += 40
                }
            }
        }
        //复制牌局编号
        private copySerialNumber(eve: egret.TouchEvent) {
            var lab: eui.Label = eve.currentTarget;
            lab.textColor = 0x459BBC;
            copyText(lab.text)
            EffectUtils.textFadeAway("复制牌局编号成功")
        }


        //显示账户明细的下拉栏
        private zhmxShowSelect(eve: egret.TouchEvent) {
            if (eve.currentTarget == this.panel.zhmxTimeBtn) {
                if (this.panel.zhmxTimeVive.visible) {
                    this.panel.zhmxTimeVive.visible = false
                } else {
                    this.panel.zhmxTimeVive.visible = true
                }
            }
            if (eve.currentTarget == this.panel.zhmxTypeBtn) {
                if (this.panel.zhmxTypeVive.visible) {
                    this.panel.zhmxTypeVive.visible = false
                } else {
                    this.panel.zhmxTypeVive.visible = true
                }
            }
            EffectUtils.playDim(eve.currentTarget)
        }
        //账户明细 - 选择时间
        private zhmxTimeSelect(eve: egret.TouchEvent) {
            this.panel.zhmxTimeLab.text = eve.currentTarget.text;
            this.panel.zhmxTimeLab.name = eve.currentTarget.name;
            this.panel.zhmxTimeVive.visible = false
            this.zhmxFind()
        }
        //账户明细 - 选择类型
        private zhmxTypeSelect(eve: egret.TouchEvent) {
            this.panel.zhmxTypeLab.text = eve.currentTarget.text;
            this.panel.zhmxTypeLab.name = eve.currentTarget.name;
            this.panel.zhmxTypeVive.visible = false
            this.zhmxFind()
        }
        //查询账户明细
        private zhmxFind() {
            var cycle = this.panel.zhmxTimeLab.name;
            var ctype = this.panel.zhmxTypeLab.name
            var time = Math.floor(Global.getCurrTimeLong() / 1000)
            var signature = Global.getSynLoginKey(time)
            signature = signature.toUpperCase()
            var request = new egret.HttpRequest();
            request.responseType = egret.HttpResponseType.TEXT;
            request.open(InstructionsEnum.IP_API + "/gameinfo/GetUserScoreDetail?uid=" + GameVO.getVo().dwUserID + "&signature=" + signature + "&time=" + time, egret.HttpMethod.POST);
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.addEventListener(egret.Event.COMPLETE, (event: egret.Event) => {
                EffectUtils.hideWaritPanel()
                try {
                    var request = <egret.HttpRequest>event.currentTarget;
                    var obj = JSON.parse(request.response)
                    if (obj.Success == 0) {
                        this.showZhmx(obj);
                    } else {
                        Global.tipShow(obj.msg)
                    }
                } catch (err) {
                    EffectUtils.textFadeAway("数据包异常，无法解析!")
                }
            }, this);
            request.addEventListener(egret.IOErrorEvent.IO_ERROR, () => {
                EffectUtils.hideWaritPanel()
                Global.tipShow("网络请求失败，请稍后重试!")
            }, this);
            EffectUtils.showWaritPanel()
            request.send("cycle=" + cycle + "&ctype=" + ctype);
        }
        //显示账户明细
        private showZhmx(obj: any) {
            var Data = obj["Data"];
            var Type = Data["Type"];
            var Sum = Data["Sum"]
            var Detail: Array<any> = Data["Detail"]
            this.panel.zhmx_chongzhi.text = Sum["recharge"]
            this.panel.zhmx_youhui.text = Sum["discount"]
            this.panel.zhmx_yue.text = Sum["balance"]
            this.panel.zhmx_tixian.text = Sum["withdraw"]
            this.panel.zhmx_fanshui.text = Sum["AgentCommision"]
            this.panel.zhmx_dataGroup.removeChildren();
            if (Detail.length == 0) {
                this.panel.zhmx_wushuju.visible = true;
            } else {
                this.panel.zhmx_wushuju.visible = false;
                var y = 10
                for (var i = 0; i < Detail.length; i++) {
                    var changeTime = Detail[i]["changeTime"]
                    var type = Detail[i]["type"]
                    var expenditure = Detail[i]["expenditure"]
                    var income = Detail[i]["income"]
                    var balance = Detail[i]["balance"]

                    var lab1 = new eui.Label(changeTime + "")
                    lab1.x = 0;
                    lab1.y = y;
                    lab1.size = 18
                    lab1.width = 190
                    lab1.textAlign = "center";
                    lab1.textColor = 0x80bf46
                    lab1.fontFamily = "Microsoft YaHei"
                    this.panel.zhmx_dataGroup.addChild(lab1)
                    var lab2 = new eui.Label(type + "")
                    lab2.x = 195;
                    lab2.y = y;
                    lab2.size = 18
                    lab2.width = 190
                    lab2.textAlign = "center";
                    lab2.textColor = 0x80bf46
                    lab2.fontFamily = "Microsoft YaHei"
                    this.panel.zhmx_dataGroup.addChild(lab2)
                    var lab3 = new eui.Label(expenditure + "")
                    lab3.x = 390;
                    lab3.y = y;
                    lab3.size = 18
                    lab3.width = 200
                    lab3.textAlign = "center";
                    lab3.textColor = 0xedb561
                    lab3.fontFamily = "Microsoft YaHei"
                    this.panel.zhmx_dataGroup.addChild(lab3)
                    var lab4 = new eui.Label(income + "")
                    lab4.x = 582;
                    lab4.y = y;
                    lab4.size = 18
                    lab4.width = 200
                    lab4.textAlign = "center";
                    lab4.textColor = 0xedb561
                    lab4.fontFamily = "Microsoft YaHei"
                    this.panel.zhmx_dataGroup.addChild(lab4)
                    var lab5 = new eui.Label(balance + "")
                    lab5.x = 780;
                    lab5.y = y;
                    lab5.size = 18
                    lab5.width = 200
                    lab5.textAlign = "center";
                    lab5.textColor = 0xedb561
                    lab5.fontFamily = "Microsoft YaHei"
                    this.panel.zhmx_dataGroup.addChild(lab5)
                    y += 40
                }

            }
        }

        //显示个人报表的下拉栏
        private grbbShowSelect(eve: egret.TouchEvent) {
            if (eve.currentTarget == this.panel.grbbTimeBtn) {
                if (this.panel.grbbTimeVive.visible) {
                    this.panel.grbbTimeVive.visible = false
                } else {
                    this.panel.grbbTimeVive.visible = true
                }
            }
            EffectUtils.playDim(eve.currentTarget)
        }
        //个人报表 - 选择时间
        private grbbTimeSelect(eve: egret.TouchEvent) {
            this.panel.grbbTimeLab.text = eve.currentTarget.text;
            this.panel.grbbTimeLab.name = eve.currentTarget.name;
            this.panel.grbbTimeVive.visible = false
            this.grbbFind()
        }
        //查询个人报表
        private grbbFind() {
            var cycle = this.panel.grbbTimeLab.name;
            var time = Math.floor(Global.getCurrTimeLong() / 1000)
            var signature = Global.getSynLoginKey(time)
            signature = signature.toUpperCase()
            var request = new egret.HttpRequest();
            request.responseType = egret.HttpResponseType.TEXT;
            request.open(InstructionsEnum.IP_API + "/gameinfo/GetUserScore?uid=" + GameVO.getVo().dwUserID + "&signature=" + signature + "&time=" + time, egret.HttpMethod.POST);
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.addEventListener(egret.Event.COMPLETE, (event: egret.Event) => {
                EffectUtils.hideWaritPanel()
                try {
                    var request = <egret.HttpRequest>event.currentTarget;
                    var obj = JSON.parse(request.response)
                    if (obj.Success == 0) {
                        this.showgrbb(obj);
                    } else {
                        Global.tipShow(obj.msg)
                    }
                } catch (err) {
                    EffectUtils.textFadeAway("数据包异常，无法解析!")
                }
            }, this);
            request.addEventListener(egret.IOErrorEvent.IO_ERROR, () => {
                EffectUtils.hideWaritPanel()
                Global.tipShow("网络请求失败，请稍后重试!")
            }, this);
            EffectUtils.showWaritPanel()
            request.send("cycle=" + cycle);
        }
        //显示个人报表
        private showgrbb(obj: any) {
            var Data = obj["Data"]
            this.panel.grbbyingli.text = Data["WinAmt"]
            this.panel.grbbyingli.textColor = Number(Data["WinAmt"]) > 0 ? 0x8aff00 : 0xff0000
            this.panel.grbbtouzhu.text = Data["ValidBetAmt"]
            this.panel.grbbfanyong.text = Data["AgentCommision"]
        }
    }
}
